<template>
  <el-dialog
    title="共享文件"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="jsbos-dialog jsbos-dialog_center transfer-dialog"
    lock-scroll
    width="800px"
    :modal="false"
  >
    <user-transfer v-model="checkedKeys" ref="userTransfer" multiple />
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{
        $t("common.cancelButton")
      }}</el-button>
      <el-button type="primary" @click="dataformSubmit()">{{
        $t("common.confirmButton")
      }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { ShareCreate, ShareUserList } from "@/api/extend/document";
import userTransfer from "@/components/user-transfer";
export default {
  components: { userTransfer },
  props: ["getShareUserId"],
  data() {
    return {
      visible: false,
      documentId: "",
      treeData: [],
      checkedKeys: [],
    };
  },
  methods: {
    init(id) {
      if (!id) return;
      this.checkedKeys = [];
      this.documentId = id;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs.userTransfer && (this.$refs.userTransfer.allLoading = true);
        ShareUserList(this.documentId).then((res) => {
          let list = res.data.list
            .filter((i) => i.shareType == "1")
            .map((o) => o.shareUserId);
          this.checkedKeys = list.length ? list : [];
          this.$refs.userTransfer && this.$refs.userTransfer.init();
        });
      });
    },
    dataformSubmit() {
      if (!this.checkedKeys.length) {
        this.$message({
          message: "请选择共享人员",
          type: "error",
          duration: 1000,
        });
        return;
      }
      this.$emit("getShareUserId", this.checkedKeys);
      this.visible = false;
    },
  },
};
</script>
